<%@ page language="java" pageEncoding="UTF-8"%>
<%@ page import="com.qijia.travel.app.*"  %>
<%@ page import="com.qijia.travel.domain.*"  %>
<%@ page import="com.qijia.travel.vo.*"  %>
<%@page import="com.qijia.travel.helper.ObjectHelper"%>
<%@page import="java.math.BigDecimal"%>
<%@page import="java.util.*"%>
<%@page import="com.qijia.travel.helper.DateHelper"%>
<%@ page import="com.qijia.travel.common.*"  %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
Guide guide = (Guide)session.getAttribute(Constants.USER_KEY);
if(guide.getGuideType()==null||guide.getGuideType()!=1){
out.println("<script>alert('你没有此权限，请联系管理员开通此权限!');window.close();</script>");
response.sendRedirect(basePath+"baseInfo/home.jsp");
}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7"/>
<title>后台管理平台--旅游网</title>
<link rel="stylesheet" type="text/css" href="../css/layout.css" />
<script language="javascript" type="text/javascript" src="<%=basePath%>js/selectall.js"></script>
<script language="javascript" type="text/javascript" src="<%=basePath%>js/trchgcolor.js"></script>
<script language="javascript" type="text/javascript" src="<%=basePath%>js/DownPullMenu.js"></script>
<script language="javascript" type="text/javascript" src="<%=basePath%>js/listOrder.js"></script>
<script language="javascript" type="text/javascript" src="<%=basePath%>js/displayLayer.js"></script>
<script language="javascript" type="text/javascript" src="<%=basePath%>js/calendar.js"></script>
<script language="javascript" type="text/javascript" src="<%=basePath%>js/popupdiv_shim.js"></script>
<script language="javascript" type="text/javascript" src="<%=basePath%>js/ajaxPopup.js"></script>
<link rel="stylesheet" type="text/css" href="<%=basePath%>js/ymPrompt/skin/qq/ymPrompt.css" />
<script type="text/javascript" src="<%=basePath%>js/ymPrompt/ymPrompt.js"></script>
</head>
<%
request.setCharacterEncoding("UTF-8");
EptManager manager = new EptManager();

try{
TouristDetailVo vo = (TouristDetailVo)ObjectHelper.ConvertURLRequsetMapToObj(request.getParameterMap(),TouristDetailVo.class);


if(vo.getEdDate()==null){//如果结束日期为空,则默认为三个月前的月份第一天
     vo.setEdDate(DateHelper.getMonthEndDay());
     if(vo.getStDate()==null){//若起始日期为空，则顺延至结束日期的前三个月的第一天
          Calendar now = Calendar.getInstance();
          now.add(Calendar.MONTH,-2);
          vo.setStDate(DateHelper.getThisMonthFirstDay(now));
     }
}

if(vo.getStDate()==null){//若起始日期为空，则顺延至结束日期的前三个月的第一天
   Calendar now = Calendar.getInstance();
   now.setTime(DateHelper.parseToDate(vo.getEdDate(),DateHelper.yyyyMMdd));
   now.add(Calendar.MONTH,-2);
   vo.setStDate(DateHelper.getThisMonthFirstDay(now));
}

PageResult pageObj = manager.selectTouristExpenditureList(vo);
EptManager eptManager = new EptManager();

vo.setIoType(1);
BigDecimal outTotal = eptManager.getOutTotal(vo);

vo.setIoType(2);
BigDecimal inTotal = eptManager.getOutTotal(vo);

TouristDetailVo lastMonth = new TouristDetailVo();
Calendar rightNow = Calendar.getInstance();
BigDecimal lastOutTotal = BigDecimal.ZERO;
BigDecimal lastInTotal = BigDecimal.ZERO;

if(vo.getStDate()!=null&&vo.getStDate().trim().length()>0){
rightNow.setTime(DateHelper.parseToDate(vo.getStDate(),DateHelper.yyyyMMdd));
rightNow.add(Calendar.MONTH,-1);
lastMonth.setEdDate(DateHelper.getThisMonthEndDay(rightNow));


//rightNow.set(Calendar.DAY_OF_MONTH,1);
//lastMonth.setStDate(DateHelper.parseToString(rightNow.getTime(),DateHelper.yyyyMMdd));

lastMonth.setIoType(1);
lastOutTotal = eptManager.getOutTotal(lastMonth);

lastMonth.setIoType(2);
lastInTotal = eptManager.getOutTotal(lastMonth);
}


BigDecimal yuer = new BigDecimal(0);
BigDecimal zero = new BigDecimal(0);

if(inTotal!=null){
yuer = yuer.add(inTotal);
}

if(outTotal!=null){
yuer = yuer.subtract(outTotal);
}

if(lastInTotal!=null){
yuer = yuer.add(lastInTotal);
}

if(lastOutTotal!=null){
yuer = yuer.subtract(lastOutTotal);
}


 %>
 <c:set var="vo" value="<%=vo%>" />
<body>
<div id="wrapper">
    <!--头部菜单开始-->
    <jsp:include page="../common/TopMenu.jsp"></jsp:include>
    <!--头部菜单结束-->
	<div id="BreadCrumb">我的位置：排团管理 &gt; 公司收支管理</div>
	<div id="REC_content">
	    <fieldset id="TalentLib" class="mainField">
		    <legend><span class="title">公司收支管理</span></legend>
			<div class="innerCon">
			    <form name="TalentLibForm" action="<%=basePath%>work/expenditure.jsp" method="post">
				<!--表头搜索条开始-->
				<div class="mainSearchBox">
				<table width="100%" cellpadding="0" cellspacing="0" border="0" class="editTab">
					<tr height="35">
						<td width="80" class="title">关键字</td>
						<td width="295" colspan="3">
						<select name="searchCode">
						    <option value="0" ></option>
							<option value="1" <%if(null!=vo.getSearchCode()&&vo.getSearchCode()==1)out.print("selected");%>>导游姓名</option>
							<option value="3" <%if(null!=vo.getSearchCode()&&vo.getSearchCode()==3)out.print("selected");%>>导游编号</option>
							<option value="9" <%if(null!=vo.getSearchCode()&&vo.getSearchCode()==9)out.print("selected");%>>收入/支出</option>
						</select> 
						<input type="text" name="searchKeyword" value="<%=vo.getSearchKeyword()==null?"":vo.getSearchKeyword()%>" size="40" /></td>
						<td width="160">
						  <input type="submit" name="searchButton" class="newSearchButton" value="查询" /> 
						</td>
					</tr>
					<tr id="moresearchCon">
						<td class="title" height="30">日期</td>
						<td colspan="4">
						<select name="dateCode">
							<option value="3" <%if(null!=vo.getDateCode()&&vo.getDateCode()==3)out.print("selected");%>>收支日期</option>
						</select>
						<input type="text" id="startImg" name="stDate" size="10" readonly="readonly" value="<%=vo.getStDate()==null?"":vo.getStDate()%>" onclick="fPopCalendar(document.getElementById('startImg'),document.getElementById('startImg'));return false;" onkeydown="iniTxt_OnKeydown(event,this);" />
					  --<input type="text" id="endImg" name="edDate" size="10" readonly="readonly" value="<%=vo.getEdDate()==null?"":vo.getEdDate()%>" onclick="fPopCalendar(document.getElementById('endImg'),document.getElementById('endImg'));return false;" onkeydown="iniTxt_OnKeydown(event,this);" />
						</td>
					</tr>
				</table>
				</div>
				<!--表头搜索条结束-->
				
			    <!-- begin tab -->
			    <div class="topControl clearfix">
				    <div id="TalentLibTabCon" class="itemTabCon">
					    <ul id="TalentLibTabs" class="itemTabs">
					        <li id="onlineTab" class="blur"><a href="<%=basePath%>baseInfo/guideManage.jsp" >导游状态管理</a></li>
						    <li id="onlineTab" class="blur"><a href="<%=basePath%>work/tourist.jsp" >排团管理</a></li>
						    <li id="onlineTab" class="blur"><a href="<%=basePath%>work/consumption.jsp" onfocus="this.blur()">团消费管理</a></li>
						    <li id="onlineTab" class="focus"><a href="<%=basePath%>work/expenditure.jsp" onfocus="this.blur()">公司收支管理</a></li>
					    </ul>
				    </div>
					<div class="leftCon"><span id="info" class="infoClass" style="display:none;"></span></div>
                    <div class="toprightCon"></div>
			    </div>
			    <!-- end tab -->
				
				<div id="mainListCon">
						<div class="infoCon clearfix">
						    <div class="leftCon">以下是符合条件的收支细项列表</div>
						    <div class="rightCon">共有 <span class="num"><%=pageObj.getRowCnt()%></span> 个收支项</div>
					    </div>
						<div class="tableCon">
						<table width="100%" border="0" cellpadding="0" cellspacing="0" id="TalentResumeList" class="listTab">
							<tr class="tabHead">
								<td class="blankTd"></td><!--从0开始算至第10项，所以性别从第11项开始算-->
								<td width="40" class="centerAlign" nowrap=nowrap>项次</td>
								<td nowrap=nowrap class="centerAlign">收支项名称</td>
								<td nowrap=nowrap class="centerAlign">收入/支出</td>
								<td width="80" class="centerAlign" nowrap=nowrap>收支类型</td>
								<td width="80" class="centerAlign" nowrap=nowrap>经手人</td>
								<td width="80" class="centerAlign" nowrap=nowrap>金额</td>
								<td width="70" class="centerAlign" nowrap=nowrap>日期</td>
								<td width="290" class="centerAlign" nowrap=nowrap>说明</td>
								<td width="70" class="centerAlign" nowrap=nowrap>创建日期</td>
							</tr>
						  <%
							 int i=0;
							   for(Object obj : pageObj.getPageList()){
							   i++;
							     TouristExpenditure detail = (TouristExpenditure)obj;
							  %>
							<tr class='<%=i%2==0?"list2":"list1"%>'>
								<td class="tdCheckbox">
								  <input type="checkbox" id="<%=detail.getExpenditureId()%>" name="chkid" onclick="unChkSelectAll('chkall')" />
								</td>
								<td class="centerAlign"><%=i%></td>
								<td class="centerAlign"><a href="#" onclick="ymPrompt.win('newExpenditure.jsp?detailId=<%=detail.getExpenditureId()%>',480,480,'修改收支信息',closeWin,null,null,true)"><%=detail.getExpenditureName()%></a></td>
								<td class="centerAlign"><%=detail.getIoType()==1?"支出":"收入"%></td>
								<td class="centerAlign"><%=detail.getExpenditureType()==null?"无":detail.getExpenditureType()%></td>
								<td class="centerAlign"><%=detail.getGuideName() %></td>
								<td class="centerAlign"><%=detail.getExpenditureAmount()==null?"":detail.getExpenditureAmount().setScale(2,BigDecimal.ROUND_HALF_UP)%></td>
								<td class="centerAlign"><%=detail.getExpenditureDate()==null?"":DateHelper.parseToString(detail.getExpenditureDate(),DateHelper.yyyyMMdd)%></td>
								<td class="centerAlign"><%=detail.getExpenditureDesc()==null?"无":detail.getExpenditureDesc()%></td>
								<td><%=detail.getExpenditureCreateDate()==null?"":DateHelper.parseToString(detail.getExpenditureCreateDate(),DateHelper.yyyyMMdd)%></td>
							</tr>
							<%
							}
							 %>
							 <tr align="center" bgcolor="lightgreen">
							    <td class="tdCheckbox"></td>
								<td colspan=2 class="centerAlign" nowrap=nowrap><h3>总计:</h3></td>
								<td nowrap=nowrap align="right" colspan="7">
								之前累积余额：<a href="expenditure.jsp?stDate=<%=lastMonth.getStDate()==null?"":lastMonth.getStDate()%>&edDate=<%=lastMonth.getEdDate()==null?"":lastMonth.getEdDate()%>" target="_blank"><font style="FONT-SIZE: 16pt; FILTER: wave(add=0,lightstrength=50,strength=3,freq=2,phrase=10); WIDTH: 100%; COLOR: <%=lastInTotal!=null&&lastOutTotal!=null&&lastInTotal.compareTo(lastOutTotal)>0?"green":"red" %>; LINE-HEIGHT: 100%; FONT-FAMILY: 华文行楷">
								<%if(lastInTotal!=null&&lastOutTotal!=null){
								    out.print(lastInTotal.subtract(lastOutTotal).setScale(2,BigDecimal.ROUND_HALF_UP));
								}else if(lastInTotal!=null){
								    out.print(lastInTotal.setScale(2,BigDecimal.ROUND_HALF_UP));
								}else if(lastOutTotal!=null){
								    out.print("-"+lastOutTotal.setScale(2,BigDecimal.ROUND_HALF_UP));
								}else
								    out.print("0.00"); %></font></a>&nbsp;&nbsp;&nbsp;&nbsp;
								
								查询支出总计:<a href="expenditure.jsp?stDate=<%=vo.getStDate()==null?"":vo.getStDate()%>&edDate=<%=vo.getEdDate()==null?"":vo.getEdDate()%>&ioType=1" target="_blank"><font style="FONT-SIZE: 16pt; FILTER: wave(add=0,lightstrength=50,strength=3,freq=2,phrase=10); WIDTH: 100%; COLOR: red; LINE-HEIGHT: 100%; FONT-FAMILY: 华文行楷"><%=outTotal==null?"0.00":outTotal%></font></a>&nbsp;&nbsp;&nbsp;&nbsp; 
								查询收入总计:<a href="expenditure.jsp?stDate=<%=vo.getStDate()==null?"":vo.getStDate()%>&edDate=<%=vo.getEdDate()==null?"":vo.getEdDate()%>&ioType=2" target="_blank"><font style="FONT-SIZE: 16pt; FILTER: wave(add=0,lightstrength=50,strength=3,freq=2,phrase=10); WIDTH: 100%; COLOR: green; LINE-HEIGHT: 100%; FONT-FAMILY: 华文行楷"><%=inTotal==null?"0.00":inTotal%></font></a>&nbsp;&nbsp;&nbsp;&nbsp; 
								余额:<font style="FONT-SIZE: 16pt; FILTER: wave(add=0,lightstrength=50,strength=3,freq=2,phrase=10); WIDTH: 100%; COLOR: <%=yuer.compareTo(zero)>0?"green":"red" %>; LINE-HEIGHT: 100%; FONT-FAMILY: 华文行楷">
								<%if(yuer!=null){
								    out.print(yuer.setScale(2,BigDecimal.ROUND_HALF_UP));
								}else
								    out.print("0.00"); %></font>
								</td>
							</tr>
							<tr align="center">
								<td colspan="10"></td>
							</tr>
						</table>
						</div>
						<!--@BeginSHOWPAGE-->
						<div class="turnpageCon clearfix">
							<div class="checkAll">
								<label for="chkall">
								  <input type="checkbox" name="chkall" id="chkall" value="1" onclick="ChkSelectAll('chkid','chkall')"/>全选</label>
						          <input type="hidden" id="curPage" name="curPage" value="${vo.curPage}"/>
						    </div>
							<div class="turnpage">
							  <%=pageObj.getSimpleBar()%>
						    </div>
						</div>
						<div class="bottomControl">
						   <input type="button" value="新增收支项" class="genButton6" onclick="ymPrompt.win('newExpenditure.jsp',480,480,'新增支出',closeWin,null,null,true)"/>&nbsp;
						   <input type="button" value="删除选中项" class="genButton6" onclick="deleteSelected()"/>&nbsp;
						   <input type="button" value="导出Excel" class="genButton6" onclick="outputExcel()"/>&nbsp;
						</div>
						<!--@EndSHOWPAGE-->
				</div>
				</form>
			</div>
		</fieldset>
	</div>
	<jsp:include page="../common/Foot.jsp"></jsp:include>
</div>
<script src="<%=basePath%>js/PaginatedTools.js"></script>
<script src="<%=basePath%>dwr/interface/eptManager.js"></script>
<script src="<%=basePath%>dwr/engine.js"></script>
<script src="<%=basePath%>js/jquery.js"></script>
<!--部门弹出窗口JS-->
<script language="javascript" type="text/javascript">
function getCheckItems(){
 var details;
 var first=0;
 $("input[name='chkid']").each(function(idx){
   if(this.checked){
      if(first==0){
         details=this.id;
         first=1;
      }else{
         details+=","+this.id;
      }
   }
 });
 return details;
}

function deleteSelected(){
 if(confirm("确定要删除掉选中的收支项吗?")){
   eptManager.deleteTouristExpenditure(getCheckItems(),function(data){
     alert("删除成功!");
     window.location.reload();
   });
 }else
   return;
}

var errorHandle = function(err){
     alert(err);
};
dwr.engine.setErrorHandler(errorHandle); 

function formSubmit(curPage){
  //window.location.href="expenditure.jsp?curPage="+curPage;
  $("#curPage").val(curPage);
  document.TalentLibForm.submit();
}
PaginatedTools.setCallBackFun(formSubmit);
function closeWin(){
}

function outputExcel(){
   document.TalentLibForm.action="<%=basePath%>work/expenditureImport.jsp";
   document.TalentLibForm.submit();
}
</script>
<%}catch(Exception e){
  out.print(e.getMessage());
  e.printStackTrace();
} %>
</body>
</html>
